#include "downloadfile.h"
#include "ui_downloadfile.h"
#include <QMessageBox>

DownloadFile::DownloadFile(QString userName, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DownloadFile)
{
    ui->setupUi(this);
    this->setWindowTitle(userName + "下载文件");
}

DownloadFile::~DownloadFile()
{
    delete ui;
}

void DownloadFile::closeEvent(QCloseEvent *event)
{
    Q_UNUSED(event)
    emit objClose();
    this->deleteLater();
}

void DownloadFile::onAllFile(QStringList files)
{
    for (auto file : files)
    {
        QListWidgetItem *item = new QListWidgetItem(file);
        item->setTextAlignment(Qt::AlignCenter);
        ui->lw_file->addItem(item);
    }
}

void DownloadFile::on_btn_download_clicked()
{
    QList<QListWidgetItem*> item = ui->lw_file->selectedItems();
    if (item.isEmpty())
    {
        QMessageBox::warning(this, "下载", "请选择文件");
        return ;
    }
    QString file = item[0]->text();
    emit download(file);
    this->deleteLater();
}
